//
//  DevicesViewCell.m
//  Runone
//
//  Created by runone01 on 16/8/11.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "DevicesViewCell.h"
#import "DeviceBaseInfo.h"
#import "AppDelegate.h"

@interface DevicesViewCell ()

@property (strong, nonatomic) NSMutableArray *upInfoBoardArray; //上行的情报板
@property (strong, nonatomic) NSMutableArray *downInfoBoardArray;//下行的情报板
@property (weak, nonatomic) IBOutlet UIView *containerView;

@property (strong, nonatomic) NSMutableArray *upCameraArray; //上行的摄像枪
@property (strong, nonatomic) NSMutableArray *downCameraArray;//下行的摄像枪

@end

@implementation DevicesViewCell

-(void)setMergeModel:(HighwayMergeInfoModel *)mergeModel {
    _mergeModel = mergeModel;
    [self classifyData:_mergeModel];
    [_StationBtn setTitle:_mergeModel.mergeName forState:UIControlStateNormal];
    
    
    if (_mergeModel.mergeType == 0) {
        _leftView.hidden  = YES;
        _rightView.hidden = YES;
    }
    if (_mergeModel.mergeType == 1) {
        _leftView.hidden  = YES;
        _rightView.hidden = YES;
    }
    if (_mergeModel.mergeType == 2 && [_mergeModel.mergeName isEqualToString:@"北连接线"]) {
        _leftView.hidden  = NO;
        _rightView.hidden = NO;
        [_ConnectingLineBtn setTitle:@"002" forState:UIControlStateNormal];
    }
    if (_mergeModel.mergeType == 2 && [_mergeModel.mergeName isEqualToString:@"南连接线"]) {
        _leftView.hidden  = NO;
        _rightView.hidden = NO;
        [_ConnectingLineBtn setTitle:@"003" forState:UIControlStateNormal];
    }
    
    if (_upInfoBoardArray.count > 0) {
        _leftInfoBoardBtn.hidden = NO;
    }
    if (_downInfoBoardArray.count > 0) {
        _rightInfoBoardBtn.hidden = NO;
    }
    if (_upCameraArray.count > 0) {
        _leftCameraBtn.hidden = NO;
    }
    if (_downCameraArray.count > 0) {
        _rightCameraBtn.hidden = NO;
    }
}
#pragma mark -将情报板和摄像枪分开
- (void) classifyData:(HighwayMergeInfoModel *)mergeModel {
    for (DeviceBaseInfo *deviceModel in mergeModel.UpWayDevices) {
        if (deviceModel.DeviceType == 2 && deviceModel.Direction == 1 ) { //上行的情报板
            [_upInfoBoardArray addObject:deviceModel];
        }
        if (deviceModel.DeviceType == 4 && deviceModel.Direction == 1) {//上行的摄像枪
            [_upCameraArray addObject:deviceModel];
        }
    }
    for (DeviceBaseInfo *deviceM in mergeModel.DownWayDevices) {
        if (deviceM.DeviceType == 2 && deviceM.Direction == 2) { //下行的情报板
            [_downInfoBoardArray addObject:deviceM];
        }
        if (deviceM.DeviceType == 4 && deviceM.Direction == 2) { //下行的摄像枪
            [_downCameraArray addObject:deviceM];
        }

    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    _leftInfoBoardBtn.hidden  = YES;
    _rightInfoBoardBtn.hidden = YES;
    _leftCameraBtn.hidden     = YES;
    _rightCameraBtn.hidden    = YES;
    
    
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    //array
    _upInfoBoardArray   = [[NSMutableArray alloc] init];
    _downInfoBoardArray = [[NSMutableArray alloc] init];
    _upCameraArray      = [[NSMutableArray alloc] init];
    _downCameraArray    = [[NSMutableArray alloc] init];
    
    _StationBtn.backgroundColor            = [UIColor whiteColor];
    _StationBtn.tag                        = 0;
    _StationBtn.layer.cornerRadius         = 10;
    [_StationBtn addTarget:self action:@selector(StationBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    _ConnectingLineBtn.backgroundColor     = [UIColor whiteColor];
    _ConnectingLineBtn.tag                 = 1;
    _ConnectingLineBtn.layer.cornerRadius  = 10;
    [_ConnectingLineBtn addTarget:self action:@selector(ConnectingLineBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    _leftInfoBoardBtn.backgroundColor      = [UIColor clearColor];
    _leftInfoBoardBtn.tag                  = 2;
    [_leftInfoBoardBtn addTarget:self action:@selector(leftInfoBoardBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    _rightInfoBoardBtn.backgroundColor     = [UIColor clearColor];
    _rightInfoBoardBtn.tag                 = 3;
    [_rightInfoBoardBtn addTarget:self action:@selector(rightInfoBoardBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    _leftCameraBtn.backgroundColor         = [UIColor clearColor];
    _leftCameraBtn.tag                     = 4;
    [_leftCameraBtn addTarget:self action:@selector(leftCameraBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    _rightCameraBtn.backgroundColor        = [UIColor clearColor];
    _rightCameraBtn.tag                    = 5;
    [_rightCameraBtn addTarget:self action:@selector(rightCameraBtnClick) forControlEvents:UIControlEventTouchUpInside];
}

- (void) StationBtnClick {
    //    self.ClickButton(0,[downCO2COModel copy]);
}

- (void) ConnectingLineBtnClick {
    //    self.ClickButton(1,[downCO2COModel copy]);
}

- (void) leftInfoBoardBtnClick {
    self.ClickButton(2,[_upInfoBoardArray copy]);
}
- (void) rightInfoBoardBtnClick {
    self.ClickButton(3,[_downInfoBoardArray copy]);
}

- (void) leftCameraBtnClick {
    self.ClickButton(4,[_upCameraArray copy]);
}

- (void) rightCameraBtnClick {
    self.ClickButton(5,[_downCameraArray copy]);
}

-(void)prepareForReuse {
    _mergeModel = nil;
    [super prepareForReuse];
}

@end
